import threading, time
from ui.uuh_window import uuh_windows
from modules.SerialHelper import get_available_ports
from PyQt5.QtCore import Qt, pyqtSlot, QThread, pyqtSignal, QObject



# 初始化子线程
class EnhancedWindow(uuh_windows):

    def __init__(self, json_path):
        # load json path
        super().__init__(json_path)

        # connect signal slot
        self.__connect_slot()

        # init ui
        self.__update_ui()

    def __update_ui(self):
        self.widget_map['port_combo'].clear()
        self.widget_map['port_combo'].addItems(get_available_ports())
        
        self.widget_map['baud_combo'].setCurrentIndex(12)
        self.widget_map['stop_combo'].setCurrentIndex(0)
        self.widget_map['data_combo'].setCurrentIndex(3)
        self.widget_map['check_combo'].setCurrentIndex(0)

    def __connect_slot(self):
        self.widget_map['btn_update'].clicked.connect(self.update_hardware_status)
        self.widget_map['btn_connect'].clicked.connect(self.connect_serial)
        
    @pyqtSlot()
    def update_hardware_status(self):
        self.__update_ui()

    @pyqtSlot()
    def connect_serial(self):
        print ("Connect Serial")